<?php
namespace Admin\Controller;
use Admin\Controller\BaseController;
class CommentController extends BaseController {

//=========================评论迷笛先生================================

    public function mrmidi_index() {
        //筛选条件
        $data = array_filter($_GET);
        if (!empty($_GET['user_name'])) {
            $data['user_name'] = array('like',"%".trim($_GET['user_name'])."%");
        }
        unset($data['p']);
        $data['comment_object'] = 1;

        $count = M('comment')->alias('c')->join('left join midi_user as u on c.comment_object_id = u.user_id')->where($data)->count();
        $page = getpage($count,10);
        $comment_arr = M('comment')->alias('c')->join('left join midi_user as u on c.comment_object_id = u.user_id')->where($data)->order('comment_id desc')->limit($page->firstRow, $page->listRows)->select();
        $this->assign('comment_arr', $comment_arr);
        $this->assign('page', $page->show());
        $this->display();
    }

//=========================评论音频================================

    public function audio_index() {
        //筛选条件
        $data = array_filter($_GET);
        if (!empty($_GET['audio_name'])) {
            $data['audio_name'] = array('like',"%".trim($_GET['audio_name'])."%");
        }
        unset($data['p']);
        $data['comment_object'] = 2;

        $count = M('comment')->alias('c')->join('left join midi_audio as a on c.comment_object_id = a.audio_id')->where($data)->count();
        $page = getpage($count,10);
        $audio_arr = M('comment')->alias('c')->join('left join midi_audio as a on c.comment_object_id = a.audio_id')->where($data)->order('comment_id desc')->limit($page->firstRow, $page->listRows)->select();
        $this->assign('audio_arr', $audio_arr);
        $this->assign('page', $page->show());
        $this->display();
    }

    //删除评论
    public function comment_del(){
        $data['comment_id'] = I('get.id');
        if (M('comment')->where($data)->delete()) {
            $this->success('删除评论成功！');
        }else{
            $this->error('删除评论失败！');
        }
    }

    //多删操作
    public function comment_delall(){
        if (empty($_GET['ids'])) {
            $this->error('没有选中项');
        }
        $data['comment_id'] = array('IN',$_GET['ids']);
        M('comment')->where($data)->delete();
        $this->success('删除成功');
    }

}